package top.yxqin.easymine;


import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import top.yxqin.easymine.PlayerData.PlayerList;
import top.yxqin.easymine.commands.onTabComplete;
import top.yxqin.easymine.commands.superdig;
import top.yxqin.easymine.commands.veinmine;
import top.yxqin.easymine.eventProcessor.OnBlockBreak;
import top.yxqin.easymine.eventProcessor.OnPlayerJoin;
import top.yxqin.easymine.eventProcessor.OnPlayerQuit;
import top.yxqin.easymine.unit.Configs;
import top.yxqin.easymine.unit.Message;

import java.util.Collection;

public final class EasyMine extends JavaPlugin
{

    @Override
    public void onEnable()
    {
        // Plugin startup logic

        Configs.PluginName=getName();
        Message.Log(getName()+" 已启用");

        Message.Log("加载配置文件");
        saveDefaultConfig();
        FileConfiguration conf=getConfig();
        Configs.loadSetting(conf);
        Message.Log("加载完成");

        /**
         * 注册事件 与 命令
         * */
        getServer().getPluginManager().registerEvents(new OnPlayerJoin(this),this);
        getServer().getPluginManager().registerEvents(new OnPlayerQuit(),this);
        getServer().getPluginManager().registerEvents(new OnBlockBreak(),this);//连锁挖矿 和 超级挖掘

        getCommand("superdig").setExecutor(new superdig());
        getCommand("veinmine").setExecutor(new veinmine());

        getCommand("superdig").setTabCompleter(new onTabComplete());
        getCommand("veinmine").setTabCompleter(new onTabComplete());

        Message.Log("刷新玩家在线列表");
        PlayerList.clear();
        Collection<Player> playerList= (Collection<Player>) Bukkit.getOnlinePlayers();
        for(Player ee:playerList)
        {
            PlayerList.addPlayer(ee.getName());
            Message.sendDirection(ee);
        }
        Message.Log("刷新完成");
    }

    @Override
    public void onDisable()
    {
        // Plugin shutdown logic
        Message.Log(getName()+" 已禁用");
    }
}
